﻿using System;
using personalplaner.business.common;
using personalplaner.common;
using personalplaner.dataprovider;

namespace personalplaner.servicemodel.common
{
	public class InitSettingsHelper : BaseDataAccess
	{
		public InitSettingsHelper(ISettingsProvider settings)
			: base(settings)
		{
		}

		public bool CheckIfOpenYearExists()
		{
			using (new WaitCursor())
			{
				try
				{
					return DataServices.CommonService.CheckIfOpenYearExists(Settings.DatabaseSettings);
				}
				catch (Exception)
				{
					//TODO: show a messagebox here with the error
				}

				return false;
			}
		}

		public int GetActiveYearId()
		{
			using (new WaitCursor())
			{
				try
				{
					return DataServices.CommonService.GetActiveYearId(Settings.DatabaseSettings/*, Settings.Mandant*/);
				}
				catch (Exception e)
				{
					//TODO: show a messagebox here with the error
					Console.Write(e);
				}

				return 0;
			}
		}

		public int GetActiveYear()
		{
			using (new WaitCursor())
			{
				try
				{
					return DataServices.CommonService.GetActiveYear(Settings.DatabaseSettings/*, Settings.Mandant*/);
				}
				catch (Exception e)
				{
					//TODO: show a messagebox here with the error
					Console.Write(e);
				}

				return 0;
			}
		}

        public string GetMandid()
        {
            using (new WaitCursor())
            {
                try
                {
                    return DataServices.CommonService.GetMandid(Settings.DatabaseSettings);
                }
                catch (Exception e)
                {
                    //TODO: show a messagebox here with the error
                    Console.Write(e);
                }

                return "";
            }
        }
	}
}
